home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 76 / XENIATGM66.iso / Indiana Jones / Indiana Jones.exe / RESOURCE / PREVIEW.GOB / cog_actor_stickyspider.cog < prev    next >
Text File  |  1999-11-15  |  7KB  |  239 lines

  1. # Jones 3D Cog Script
  2. #
  3. # actor_StickySpider.cog
  4. #
  5. # [RT] [MDR]
  6. #
  7. # ### Notes ###
  8. # The sticky spider can be made to "drop on a web" manually if triggered by a USER0 message
  9. # from COG as follows:
  10. #
  11. #   SendMessageEx( GetThingClassCog(THINGREF spider), USER0, (THINGREF spider), 0, 0, 0 );
  12. #
  13. # (C) 1999 LucasArts Entertainment Company LLC. All Rights Reserved
  14. #
  15. # ========================================================================================
  16. symbols
  17.  
  18.     message        created
  19.     message        aievent
  20.     message        killed
  21.     message        timer
  22.     message        user0
  23.  
  24. # ************************** TEMPLATES *************************
  25. template    tpl_Spider=spider            local
  26. material    mat_web=gen_a4web.mat
  27.  
  28. # ************************** MISC LOCAL VARS *******************
  29. thing        t_StickySpider                local
  30. thing        t_NewSpider                    local
  31. thing        t_web                        local
  32. flex        f_maxWebAlpha=0.3            local
  33. int            FLAG_WEBDROP=1                local
  34. flex        f_userData                    local
  35.  
  36. int            bPaused=0                    local
  37. vector        vec_look                    local
  38. vector        vec_pyr                        local
  39. sector        sec_atNewPos                local
  40.  
  41. cog            cog_capture                    local
  42.  
  43. # ************************ SUBROUTINES *************************
  44. flex        WebDrop                        local
  45. flex        MakeRealSpider                local
  46. flex        KillWeb                        local
  47.  
  48. end
  49.  
  50. # =================================================================================
  51. code
  52.  
  53. # .................................................................................    
  54. created:
  55.     
  56.     SetThingUserData(GetSenderRef(), 0);
  57.     return;
  58.  
  59.  
  60. # .................................................................................    
  61. aievent:
  62.  
  63.     t_StickySpider = GetSenderRef();
  64.  
  65.     if ( GetParam(0) == 0x100 )                                    #---- EVENT_MODECHANGED
  66.     {                                                                # Switched to MODE_ATTACKING?
  67.         if ( BITTEST(GetParam(1), 0x02) && !BITTEST(GetParam(2), 0x02) )
  68.         {
  69.             f_userData    = GetThingUserData(t_StickySpider);
  70.  
  71.             if ( (GetAttachFlags(t_StickySpider) > 0) && !BITTEST(f_userData, FLAG_WEBDROP) )
  72.             {
  73.                 call WebDrop;
  74.             }
  75.         }
  76.     }
  77.  
  78.     return;
  79.  
  80.  
  81. # .................................................................................    
  82. killed:
  83.  
  84.     t_StickySpider = GetSenderRef();
  85.  
  86.     SetThingTimer(t_StickySpider, 0);
  87.     SetPhysicsFlags(t_StickySpider, 0x1);
  88.  
  89.     DetachThing(t_StickySpider);
  90.  
  91.     vec_look    = GetThingLVecPYR(t_StickySpider);
  92.     vec_pyr        = VectorSet(0, VectorY(vec_look), VectorZ(vec_look));
  93.     SetThingLVecPYR(t_StickySpider, vec_pyr);
  94.  
  95.     call KillWeb;
  96.  
  97.     return;
  98.  
  99.  
  100. # .................................................................................    
  101. timer:
  102.     t_StickySpider = GetSenderRef();
  103.     bPaused = !BITTEST(GetPhysicsFlags(t_StickySpider), 0x1);
  104.  
  105.     if (bPaused || VectorZ(GetThingVel(t_StickySpider)) < 0.0)
  106.     {
  107.         if (!bPaused)
  108.         {
  109.             StopThing(t_StickySpider);
  110.             ClearPhysicsFlags(t_StickySpider, 0x1);            # disable gravity
  111.             SetThingTimer(t_StickySpider, Rand() + 0.1);
  112.         }
  113.         else
  114.         {
  115.             SetPhysicsFlags(t_StickySpider, 0x1);            # enable gravity
  116.             SetThingTimer(t_StickySpider, Rand()/3 + 0.1);
  117.         }
  118.     }
  119.     else
  120.     {
  121.         call KillWeb;
  122.         call MakeRealSpider;
  123.  
  124. #        CreateThing(tpl_Spider, t_StickySpider);            # Make a real spider
  125. #        DestroyThing(t_StickySpider);                        # Get rid of the sticky spider
  126.     }
  127.  
  128.     return;
  129.  
  130.  
  131. # .................................................................................    
  132. user0:
  133.  
  134.     t_StickySpider    = GetParam(0);                                # THINGREF for spider on wall
  135.     if ( GetThingType(t_StickySpider) == 2 )                    # Its a SITH_THING_ACTOR?
  136.     {
  137.         call WebDrop;
  138.     }
  139.  
  140.     return;
  141.  
  142.  
  143. # ===================================================================
  144. #    Subroutines
  145. # ===================================================================
  146.  
  147. # ...................................................................
  148. # t_StickySpider must be initialized!
  149. # ...................................................................
  150. WebDrop:
  151.  
  152.     DetachThing(t_StickySpider);
  153.     t_web = 0;                                                    # initialize to 'not created'
  154.  
  155.     // Spider only "stutter drops" if -180 < pitch < -90
  156.     if ((VectorDot(GetThingUVec(t_StickySpider), '0 0 -1') > 0) && (GetLocalPlayerThing() > -1))
  157.     {
  158.         ClearPhysicsFlags(t_StickySpider, 0x800);                # Prevent engine orientation changes
  159.         SetActorFlags(t_StickySpider, 0x40000);                    # Prevent mid air AI motion
  160.  
  161.         vec_pyr        = VectorSet(0, RandBetween(-30, 30), 0);
  162.  
  163.         vec_look    = VectorSub(GetThingPos(GetLocalPlayerThing()), GetThingPos(t_StickySpider));
  164.         vec_look    = VectorSet(VectorX(vec_look), VectorY(vec_look), -4);
  165.         vec_look    = VectorRotate(vec_look, vec_pyr);
  166.  
  167.         SetThingLook(t_StickySpider, vec_Look);                    # Set a randomized look dir
  168.  
  169.         # make a web starting at current pos
  170.         t_web = CreatePolylineThing(t_StickySpider, -1, GetThingPos(t_StickySpider), mat_web, 0.0015, 0.0015, 0);
  171.  
  172.         if (t_web > -1)
  173.         {
  174.             # Move the web back a little towards its tail
  175.             vec_pyr         = VectorTransformToOrient(t_StickySpider, '0 -0.026 -0.03');
  176.             vec_pyr         = VectorAdd(vec_pyr, GetThingPos(t_StickySpider));
  177.             sec_atNewPos = FindNewSectorFromThing(t_StickySpider, vec_pyr);
  178.             if (sec_atNewPos > -1)
  179.             {
  180.                 SetThingPosEX(t_web, vec_pyr, sec_atNewPos);
  181.             }
  182.             AttachThingToThingEx(t_web, t_StickySpider, 0x08);
  183.  
  184.             SetThingAlpha(t_web, f_maxWebAlpha);
  185.             SetThingTimer(t_StickySpider, Rand()/3 + 0.1);        # start the dropping process
  186.         }
  187.  
  188.         SetThingUserData(t_StickySpider, FLAG_WEBDROP);            # Mark as 'dropping'
  189.     }
  190.     else
  191.     {
  192.         call MakeRealSpider;                                    # Just make a real spider
  193.  
  194. #        CreateThing(tpl_Spider, t_StickySpider);
  195. #        DestroyThing(t_StickySpider);                            # Get rid of the sticky spider
  196.     }
  197.  
  198.     return;
  199.  
  200.  
  201. # ...................................................................
  202. # t_StickySpider must be initialized!
  203. # ...................................................................
  204. KillWeb:
  205.  
  206.     t_web = GetThingAttachedThing(t_StickySpider, 14);            # Get spider web handle (SITH_THING_POLYLINE)
  207.  
  208.     if ( t_web > -1 )
  209.     {
  210.         DetachThing(t_web);
  211.         ThingFadeAnim(t_web, f_maxWebAlpha, 0, 2, 0);            # Fade web out over 2 sec
  212.         SetLifeLeft(t_web, 3);                                    # Destroy it in 3 sec
  213.     }
  214.  
  215.     return;
  216.  
  217.  
  218. # ...................................................................
  219. # t_StickySpider must be initialized!
  220. # ...................................................................
  221. MakeRealSpider:
  222.  
  223.     t_NewSpider = CreateThing(tpl_Spider, t_StickySpider);            # Just make a real spider
  224.  
  225.     # If wall spider had a capture COG, pass on to the real one
  226.     cog_capture = GetThingCaptureCog(t_StickySpider);
  227.     if ( (t_NewSpider > -1) && (cog_capture > -1) )
  228.     {
  229.         SetThingCaptureCog(t_NewSpider, cog_capture);
  230.     }
  231.  
  232.     DestroyThing(t_StickySpider);                                    # Get rid of the sticky spider
  233.  
  234.     return;
  235.  
  236.  
  237. end
  238.  
  239.